import 'package:finance_app/generated/json/base/json_convert_content.dart';
import 'package:finance_app/generated/json/base/json_field.dart';
import 'package:finance_app/src/utils/date_time_utils.dart';

class SubBillingItemEntity with JsonConvert<SubBillingItemEntity> {
  int id;
  @JSONField(name: "coupon_id")
  dynamic couponId;
  @JSONField(name: "user_id")
  int userId;
  @JSONField(name: "payment_gateway_id")
  dynamic paymentGatewayId;
  @JSONField(name: "company_id")
  int companyId;
  @JSONField(name: "company_name")
  String companyName;
  @JSONField(name: "plan_id")
  int planId;
  @JSONField(name: "plan_name")
  String planName;
  @JSONField(name: "start_at")
  String startAt;
  @JSONField(name: "end_at")
  String endAt;
  @JSONField(name: "issued_at")
  String issuedAt;
  @JSONField(name: "due_at")
  dynamic dueAt;
  @JSONField(name: "notified_at")
  dynamic notifiedAt;
  int renew;
  @JSONField(name: "bill_to_company_id")
  int billToCompanyId;
  @JSONField(name: "bill_phone_number")
  String billPhoneNumber;
  @JSONField(name: "bill_contact_name")
  String billContactName;
  @JSONField(name: "bill_postal_code")
  String billPostalCode;
  @JSONField(name: "bill_unit_number")
  String billUnitNumber;
  @JSONField(name: "bill_address")
  String billAddress;
  @JSONField(name: "bill_company_name")
  String billCompanyName;
  @JSONField(name: "bill_country_code")
  dynamic billCountryCode;
  @JSONField(name: "payment_gateway_status")
  dynamic paymentGatewayStatus;
  @JSONField(name: "payment_method")
  String paymentMethod;
  @JSONField(name: "card_number")
  dynamic cardNumber;
  @JSONField(name: "next_price")
  num nextPrice;
  num price;
  @JSONField(name: "original_price")
  num originalPrice;
  String status;
  @JSONField(name: "created_at")
  String createdAt;
  @JSONField(name: "updated_at")
  String updatedAt;
  @JSONField(name: "deleted_at")
  dynamic deletedAt;

  @JSONField(name: "currency_code")
  String currencyCode;

  String currentDate;

  String get billingPeriod {
    if (this.startAt != null && this.endAt != null) {
      DateTime from = DateTime.parse(this.startAt);
      DateTime until = DateTime.parse(this.endAt);
      bool sameYear = from.year == until.year;
      return '${DateTimeUtils.formatDateTime(from, sameYear ? 'd MMM' : 'd MMM yyyy')} - ${DateTimeUtils.formatDateTime(until, 'd MMM yyyy')}';
    } else {
      return null;
    }
  }
}
